function getURL()
{
	var host=window.location.host;
	var url="http://"+host+"/DV/DienThoai";
	return url;
}
function Register()
{	
	var URL1=getURL();
	//alert(URL1);false;
		var emailRg = $("#emailRg").val();
		var pass1 = $("#pass1").val();
		var pass2 = $("#pass2").val();
		var name = $("#name").val();
		var mobile = $("#mobile").val();
		var address = $("#address").val();
		var email_regex = /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
		
	//---------------------------------------------------------------------------------------------------------------------------	
		if(emailRg == "") {//kiểm tra email rỗng
           $("#emailError1").slideDown('slow').delay(1000).slideUp('slow');
           $("#emailRg").focus();
           return false;
        }			
	
		if(!email_regex.test(emailRg)) {//kiểm tra email đúng định dạng
           $("#emailError2").slideDown('slow').delay(1000).slideUp('slow');
           $("#emailRg").focus();
           return false;
        }			
	//--------------------------------------------------------------------------------------------------------------------------	
		if(pass1 == "" || pass1.length < 6 ) {//kiểm tra pass1
           $("#pass1Error").slideDown('slow').delay(1000).slideUp('slow');
           $("#pass1").focus();
           return false;
        }			
		
		if(pass2 == "" || pass2.length < 6) {//kiểm tra pass 2
           $("#pass2Error1").slideDown('slow').delay(1000).slideUp('slow');
           $("#pass2").focus();
           return false;
        }			
		
		if( pass1 != pass2) {//ktra mật khẩu trùng nhau
           $("#pass2Error2").slideDown('slow').delay(1000).slideUp('slow');
           $("#pass2").focus();
           return false;
        }		
	//----------------------------------------------------------------------------------------------------------------------------	
		if(name == "") {//kiểm tra tên người dùng
           $("#nameError1").slideDown('slow').delay(1000).slideUp('slow');
           $("#name").focus();
           return false;
        }		
		if(name.length < 4) {//kiểm tra tên người dùng
           $("#nameError2").slideDown('slow').delay(1000).slideUp('slow');
           $("#name").focus();
           return false;
        }		
	//--------------------------------------------------------------------------------------------------------------------------------	
		if(mobile == "") {//kiểm tra SĐT
           $("#mobileError1").slideDown('slow').delay(1000).slideUp('slow');
           $("#mobile").focus();
           return false;
        }		
		if(mobile.length >14 || mobile.length < 10) {//kiểm tra SĐT
           $("#mobileError2").slideDown('slow').delay(1000).slideUp('slow');
           $("#mobile").focus();
           return false;
        }		
		
		if(parseInt(mobile) != mobile) {//kiểm tra SĐT
           $("#mobileError3").slideDown('slow').delay(1000).slideUp('slow');
           $("#mobile").focus();
           return false;
        }		
	//-------------------------------------------------------------------------------------------------------------------------------------	
		if(address == "") {//kiểm tra địa chỉ
           $("#addressError1").slideDown('slow').delay(1000).slideUp('slow');
           $("#address").focus();
           return false;
        }		
		if(address.length < 12) {//kiểm tra địa chỉ
           $("#addressError2").slideDown('slow').delay(1000).slideUp('slow');
           $("#address").focus();
           return false;
        }
	//---------------------------------------------------------------------------------------------------------------------------		
		var data_string ='email=' + emailRg 
						+ '&password=' + pass1 
						+ '&myname=' + name
						+ '&mobile=' + mobile 
						+ '&address=' + address;
		//alert(data_string);return false;
		
		$("#loading").html("<img src='http://dendau.net/images/loading.gif'/>").fadeIn('fast');
            $.ajax({
                type: "POST",
                
				url: URL1+'/members/register2',
                data: data_string,
                success: function(data_form) {
				//alert(data_form);false;
                    if(data_form == "true") {
                        $('#loading').fadeOut('fast');
                        $("#success").slideDown('slow').delay(4000).slideUp('slow');
						showHome1();
                    } 
					else if(data_form == "1"){
						$('#loading').fadeOut('fast');
                        $("#error1").slideDown('slow').delay(1000).slideUp('slow');
					}		
					else {	
                        $('#loading').fadeOut('fast');
                        $("#error").slideDown('slow').delay(1000).slideUp('slow');
                    }
                }
                });
        return false;
	
}	

function Update()
{	
	var URL1=getURL();
	//alert(URL1);false;
		var emailRg = $("#emailRg").val();
		var name = $("#name").val();
		var mobile = $("#mobile").val();
		var address = $("#address").val();
	//-----------------------------------------------------------------------------------------------------------------------------	
		if(name == "") {//kiểm tra tên người dùng
           $("#nameError1").slideDown('slow').delay(1000).slideUp('slow');
           $("#name").focus();
           return false;
        }		
		if(name.length < 4) {//kiểm tra tên người dùng
           $("#nameError2").slideDown('slow').delay(1000).slideUp('slow');
           $("#name").focus();
           return false;
        }		
	//--------------------------------------------------------------------------------------------------------------------------------	
		if(mobile == "") {//kiểm tra SĐT
           $("#mobileError1").slideDown('slow').delay(1000).slideUp('slow');
           $("#mobile").focus();
           return false;
        }		
		if(mobile.length >14 || mobile.length < 10) {//kiểm tra SĐT
           $("#mobileError2").slideDown('slow').delay(1000).slideUp('slow');
           $("#mobile").focus();
           return false;
        }		
		
		if(parseInt(mobile) != mobile) {//kiểm tra SĐT
           $("#mobileError3").slideDown('slow').delay(1000).slideUp('slow');
           $("#mobile").focus();
           return false;
        }		
	//-------------------------------------------------------------------------------------------------------------------------------------	
		if(address == "") {//kiểm tra địa chỉ
           $("#addressError1").slideDown('slow').delay(1000).slideUp('slow');
           $("#address").focus();
           return false;
        }		
		if(address.length < 12) {//kiểm tra địa chỉ
           $("#addressError2").slideDown('slow').delay(1000).slideUp('slow');
           $("#address").focus();
           return false;
        }
	//---------------------------------------------------------------------------------------------------------------------------		
		var data_string ='&myname=' + name
						+ '&mobile=' + mobile 
						+ '&address=' + address;
		//alert(data_string);return false;
		
		$("#loading").html("<img src='http://dendau.net/images/loading.gif'/>").fadeIn('fast');
            $.ajax({
                type: "POST",
                
				url: URL1+'/members/update',
                data: data_string,
                success: function(data_form) {
				//alert(data_form);false;
                    if(data_form == "true") {
                        $('#loading').fadeOut('fast');
                        $("#success").slideDown('slow').delay(4000).slideUp('slow');
						//showHome1();
                    } 
					else if(data_form == "1"){
						$('#loading').fadeOut('fast');
                        $("#error1").slideDown('slow').delay(1000).slideUp('slow');
					}		
					else {	
                        $('#loading').fadeOut('fast');
                        $("#error").slideDown('slow').delay(1000).slideUp('slow');
                    }
                }
                });
        return false;
	
}	

function ResetPass()
{	
	var URL1=getURL();
	//alert(URL);false;
		var emailRg = $("#emailRg").val();
		var mobile = $("#mobile").val();

		var email_regex = /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
		
	//---------------------------------------------------------------------------------------------------------------------------	
		if(emailRg == "") {//kiểm tra email rỗng
           $("#emailError1").slideDown('slow').delay(1000).slideUp('slow');
           $("#emailRg").focus();
           return false;
        }			
	
		if(!email_regex.test(emailRg)) {//kiểm tra email đúng định dạng
           $("#emailError2").slideDown('slow').delay(1000).slideUp('slow');
           $("#emailRg").focus();
           return false;
        }			
	//--------------------------------------------------------------------------------------------------------------------------	
		if(mobile == "") {//kiểm tra SĐT
           $("#mobileError1").slideDown('slow').delay(1000).slideUp('slow');
           $("#mobile").focus();
           return false;
        }		
		if(mobile.length >14 || mobile.length < 10) {//kiểm tra SĐT
           $("#mobileError2").slideDown('slow').delay(1000).slideUp('slow');
           $("#mobile").focus();
           return false;
        }		
		
		if(parseInt(mobile) != mobile) {//kiểm tra SĐT
           $("#mobileError3").slideDown('slow').delay(1000).slideUp('slow');
           $("#mobile").focus();
           return false;
        }		
	//-------------------------------------------------------------------------------------------------------------------------------------			
		var data_string ='email=' + emailRg + '&mobile=' + mobile;
		alert(URL1);return false;
		
		$("#loading").html("<img src='http://dendau.net/images/loading.gif'/>").fadeIn('fast');
            $.ajax({
                type: "POST",
                
				url: URL1+'/accounts/resetpassword',
                data: data_string,
                success: function(data_form) {
				alert(data_form);false;
                    if(data_form == "true") {
                        $('#loading').fadeOut('fast');
                        $("#success").slideDown('slow').delay(4000).slideUp('slow');
						showHome1();
                    } 		
					else {	
                        $('#loading').fadeOut('fast');
                        $("#error").slideDown('slow').delay(1000).slideUp('slow');
                    }
                }
                });
        return false;
	
}	
function changePass()
{	
		var URL1=getURL();
		var old_pass = $("#old_pass").val();
		var newPass1 = $("#newPass1").val();
		var newPass2 = $("#newPass2").val();
	
		if(old_pass == "" || old_pass == "Nhập mật khẩu cũ của bạn." || old_pass.length < 6 ) {
           $("#old_passError").slideDown('slow').delay(1000).slideUp('slow');
           $("#old_pass").focus();
           return false;
        }			
		
		if(newPass1 == "" || newPass1 == "Nhập mật khẩu mới." || newPass1.length < 6 ) {
           $("#newPass1Error").slideDown('slow').delay(1000).slideUp('slow');
           $("#newPass1").focus();
           return false;
        }			
		
		if(newPass2 == "" || newPass2 == "Nhập lại mật khẩu mới." || newPass2.length < 6) {
           $("#newPass2Error").slideDown('slow').delay(1000).slideUp('slow');
           $("#newPass2").focus();
           return false;
        }			
		
		if( newPass2 != newPass1) {
           $("#newPass2Error2").slideDown('slow').delay(1000).slideUp('slow');
           $("#newPass2").focus();
           return false;
        }		

		var data_string ='old_pass=' + old_pass + '&newPass1=' + newPass1 + '&newPass2=' + newPass2;
		//alert(data_string);return false;
		$("#loading").html("<img src='http://dendau.net/images/loading.gif'/>").fadeIn('fast');
            $.ajax({
                type: "POST",
                url:URL1+"/members/changePass2",
                data: data_string,
                success: function(data_form) {
				//alert(data_form);return false;
                    if(data_form == "true") {
                        $('#loading').fadeOut('fast');
                        $("#success").slideDown('slow').delay(1000).slideUp('slow');
						//showUser();
                    } 
					else if(data_form == "1"){
						$('#loading').fadeOut('fast');
                        $("#error1").slideDown('slow').delay(1000).slideUp('slow');
					}					
					else {	
                        $('#loading').fadeOut('fast');
                        $("#error").slideDown('slow').delay(1000).slideUp('slow');
                    }
                }
                });
        return false;
}	
function showHome1()
{
	//setTimeout(showHome(),50000);
	//t=setTimeout("showHome()",20000);
	setTimeout("showHome()", 2000);
}
function showHome()
{
	var URL1=getURL();
	window.location.href=URL1;
}


